package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class RemoveOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书");
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入要删除的书名");
        String name=scan.nextLine();
        int size=bookList.getSize();
        int pos=-1;
        for(int i=0;i<size;i++){
            Book book=bookList.getBooks(i);
            if(book.getName().equals(name)){
                pos=i;
                break;
            }
        }
        if(pos!=-1){
            for(int i=pos;i<size-1;i++){
                Book tmp=bookList.getBooks(i+1);
                bookList.setBooks(i,tmp);
            }
            bookList.setSize(size-1);
            System.out.println("删除成功");
            return ;
        }
        System.out.println("删除失败");
    }
}
